package rensoft.jre;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import static cs.java.lang.Lang.exception;
import static cs.java.lang.Lang.unsuported;

import cs.java.json.JSON;
import cs.java.lang.Lang.Work;
import cs.java.lang.LangCore;
import cs.java.lang.LangCoreImplBase;
import cs.java.lang.Run;

public class JreLangCoreImpl extends LangCoreImplBase implements LangCore {

	public void alert(Object... messages) {
		System.out.print(getAlertString(messages) + "\n");
	}

	@Override public void debug(Object... values) {
		System.out.print(getDebugString(values) + "\n");
	}

	@Override public void doLater(int delay_miliseconds, Runnable runnable) {
		throw unsuported();
	}

	@Override public void doLater(Runnable runnable) {
		throw unsuported();
	}

	@Override public void error(Throwable e, Object... values) {
		System.out.print(getErrorString(e, values) + "\n");
	}

	@Override public void info(Object... values) {
		System.out.print(getInfoString(values) + "\n");
	}

	@Override public JSON json() {
		throw unsuported();
	}

	@Override public Work schedule(int delay_miliseconds, Run runnable) {
		throw unsuported();
	}

	@Override public void trace(Object... values) {
		System.out.println(createLogMessage(INFO_TITLE, createTraceString(new Throwable()), values));
	}

	public String urlEncode(String argument) {
		try {
			return URLEncoder.encode(argument, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			throw exception(e);
		}
	}

}
